package Gui;

/*
 * HorizontalButtonPanel - several JButtons in a single row.
 * 
 * Usage:
 *   String[] stringarray = {"ButtonName0","ButtonName1",...};
 *   ActionListener[] listenerarray = {
 *     new ActionListener(){
 *       @Override
 *       public void actionPerformed(ActionEvent e) {
 *         // Action code when button0 pressed
 *       }
 *     }, 
 *     new ActionListener(){
 *       @Override
 *       public void actionPerformed(ActionEvent e) {
 *         // Action code when button1 pressed
 *       }
 *     }, ... };
 *   HorizontalButtonPanel hbp = new HorizontalButtonPanel( stringarray, listenerarray );
 *   
 * Example: see Gui.Dialogs.SellDealCardDialog
 */

import java.awt.GridLayout;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

public class HorizontalButtonPanel extends JPanel {

	private JPanel thepanel;
	private JButton[] buttons = null;
	private int numbuttons;

	public HorizontalButtonPanel(String[] args, ActionListener[] funcs) {

		thepanel = this;
		thepanel.setName("HorizontalButtonPanel");

		if (args != null && args.length > 0) {
			numbuttons = args.length;
			buttons = new JButton[numbuttons];

			thepanel.setLayout(new GridLayout(1, numbuttons, 5, 0));

			for (int i = 0; i < numbuttons; i++) {
				buttons[i] = new JButton(args[i]);
				if (funcs != null && i < funcs.length) {
					buttons[i].addActionListener(funcs[i]);
				}
				thepanel.add(buttons[i]);
			}
		}
	}

	public JPanel getPanel() {
		return thepanel;
	}

	public JButton getButton(int index) {
		if (index >= 0 && index < numbuttons) {
			return buttons[index];
		} else {
			return null;
		}
	}

}
